package com.shwread.android.ui.page;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.text.TextUtils;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.PopupWindow;
import android.widget.ProgressBar;
import android.widget.TextView;
import android.widget.Toast;

import com.NewActionHelp;
import com.google.gson.reflect.TypeToken;
import com.netease.nim.demo.contact.cache.TeamDataCache;
import com.netease.nim.demo.contact.cache.TeamMemberInfoCache;
import com.netease.nimlib.sdk.NIMClient;
import com.netease.nimlib.sdk.Observer;
import com.netease.nimlib.sdk.RequestCallback;
import com.netease.nimlib.sdk.StatusCode;
import com.netease.nimlib.sdk.auth.AuthServiceObserver;
import com.netease.nimlib.sdk.msg.MsgService;
import com.netease.nimlib.sdk.msg.constant.SessionTypeEnum;
import com.netease.nimlib.sdk.msg.model.RecentContact;
import com.netease.nimlib.sdk.team.TeamService;
import com.netease.nimlib.sdk.team.model.DismissAttachment;
import com.netease.nimlib.sdk.team.model.Team;
import com.shwread.android.qysw.activity.BaseSimpleActivity;
import com.shwread.android.qysw.activity.MainActivity;
import com.shwread.android.qysw10000182.R;
import com.shwread.android.ui.dialog.NoNetDialog;
import com.shwread.android.ui.dialog.VersionDialog;
import com.shwread.android.ui.page.chat.ChatTabPage;
import com.shwread.http.base.ObjectHttpResponseHandler;
import com.shwread.http.util.Logger;
import com.shwread.httpsdk.http.callback.ActionListener;
import com.shwread.httpsdk.http.face.QryNewVersionAction;
import com.tgx.tina.android.ipc.framework.IUIPage;

import org.apache.http.Header;
import org.geometerplus.android.util.QyreaderPerferencesUtil;

import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.lang.reflect.Type;
import java.net.URL;
import java.net.URLConnection;
import java.util.ArrayList;
import java.util.List;

import base.tina.core.task.infc.ITaskResult;
import logic.bean.AppInfo;
import logic.bean.Area;
import logic.bean.TeamMemberX;
import logic.constants.AppConfig;
import logic.constants.Const;
import logic.constants.DefaultConsts;
import logic.dao.AreaDao;
import logic.util.AppUtils;
import logic.util.FileUtil;
import logic.util.NetworkUtil;
import logic.util.SDcardUtil;
import logic.util.ScreenUtil;
import logic.util.Util;

/**
 * 项目名称：Association
 * 包名称：com.shwread.android.ui.page
 * 类描述：
 * 创建人： wayne
 * 创建时间 2016/1/26 16:01.
 */
public class MainTabPage extends AbstractUIPage<MainActivity> implements View.OnClickListener {


    public static final int TAG_TAB1 = 0;
    public static final int TAG_TAB2 = 1;
    public static final int TAG_TAB3 = 2;
    public static final int TAG_TAB4 = 3;
    public static final int TAG_TAB5 = 4;

    public static List<AbstractUIPage<MainActivity>> pages;

    private int pageSelected = TAG_TAB1;

    private ViewPager vpPager;
    private View vTab1;
    private View vTab2;
    private View vTab3;
    private View vTab4;
    private View vTab5;

    public static MainTabPage instance;
    private BoutiquePage boutiquePage;
    private MyWorkPage workIndexPage;
    private NewEnterprisePage enterprisePage;
    private ChatTabPage chatPage;
    private NewTrainingExamPage newTrainingExamPage;
    //    private MyHealthyPage myHealthyPage;
    private NewsPage newsPage;
    private AppInfo versionInfo;
    private VersionDialog versionDialog;
    private PopupWindow forceUpdatePop;
    private TextView update_popup_cancel;

    private ProgressBar update_popup_progress;
    private TextView update_popup_text_progress;
    private String tempFilePath;
    private AbstractUIPage<MainActivity> page;
    private static Adapter pagerAdapter;

    private MainTabPage(MainActivity t) {
        super(t);
    }

    public static MainTabPage getInstance(MainActivity t) {
        if (instance == null) instance = new MainTabPage(t);
        return instance;
    }

    public int getPageSelected() {
        return pageSelected;
    }

    public void setPageSelected(int pageSelected) {
        this.pageSelected = pageSelected;
    }

    @Override
    public <E extends Activity> View createView(E arg0, int arg1) {
        if (curMyView != null) return curMyView;

        curMyView = bActivity.getLayoutInflater().inflate(R.layout.activity_maintab, null);
        startCheckVersion();
        initView();
        initPage();
        setListeners();
        setNetImObserver();
        preload();
        return curMyView;
    }

    void initView() {
        vpPager = (ViewPager) curMyView.findViewById(R.id.main_pager);
        vTab1 = curMyView.findViewById(R.id.main_tab1);
        vTab2 = curMyView.findViewById(R.id.main_tab2);
        vTab3 = curMyView.findViewById(R.id.main_tab3);
        vTab4 = curMyView.findViewById(R.id.main_tab4);
        vTab5 = curMyView.findViewById(R.id.main_tab5);
        pagerAdapter = new Adapter();
    }

    private void setListeners() {
        vTab1.setOnClickListener(this);
        vTab2.setOnClickListener(this);
        vTab3.setOnClickListener(this);
        vTab4.setOnClickListener(this);
        vTab5.setOnClickListener(this);
        vpPager.setOnPageChangeListener(new PageChangeListener());
    }

    private void setNetImObserver() {
        // observers
        NIMClient.getService(AuthServiceObserver.class).observeOnlineStatus(userStatusObserver, true);
    }

    /**
     * **************************** 用户状态变化 *******************************
     */

    Observer<StatusCode> userStatusObserver = new Observer<StatusCode>() {

        @Override
        public void onEvent(StatusCode code) {
            switch (code) {
                case KICKOUT:
                case PWD_ERROR:
                    kickOut();
                    break;
                default:
                    break;
            }
        }
    };

    private void kickOut() {
        //
        //		LogUtil.i("Auth", "Kicked!");
        //		Utils.showToast(bActivity, "账号在其他设备登录");
        Intent intent = new Intent(DefaultConsts.EXCEPTION_LOGIN_STRING);
        intent.putExtra("json", "1003");
        intent.putExtra("packageName", AppUtils.getPackageName(context));
        context.sendBroadcast(intent);
    }

    private void setDefaultPage(int type) {
        vTab3.setSelected(true);
        boutiquePage.createView(bActivity, DEFAULT_STATUS);
        vpPager.setCurrentItem(type);
        onSelected(type);
    }

    private void initPage() {
        pages = new ArrayList<>();

        boutiquePage = BoutiquePage.getInstance(bActivity);
        newTrainingExamPage = NewTrainingExamPage.getInstance(bActivity);
        workIndexPage = MyWorkPage.getInstance(bActivity);
        enterprisePage = NewEnterprisePage.getInstance(bActivity);
        chatPage = ChatTabPage.getInstance(bActivity);
        newsPage=NewsPage.getInstance(bActivity);

        /** 如果打包需求没有个人书架，此行要注销 */
        QyreaderPerferencesUtil.getInstance(context, Const.phone_number).setExistBookShelfPage(true);
        pages.add(boutiquePage);
        pages.add(enterprisePage);
        pages.add(newsPage);
        pages.add(chatPage);
//        pages.add(newTrainingExamPage);
//        pages.add(workIndexPage);




        vpPager.setAdapter(pagerAdapter);
        pagerAdapter.notifyDataSetChanged();
        setDefaultPage(pageSelected);
        //		qryUnReadTotal();
    }

    //	private void qryUnReadTotal() {
    //		//获取未读消息总条数
    //		new QryUnReadTotalAction(bActivity, DefaultConsts.TYPE_WRITESOURCE_ENTERPRISE, new GetUnreadAction(true)).start();
    //		new QryUnReadTotalAction(bActivity, DefaultConsts.TYPE_WRITESOURCE_SYSTEM, new GetUnreadAction(false)).start();
    //	}

    @Override
    public int enter(IUIPage<?> arg0) {
        onSelected(pageSelected);
//        getAllCity();
        return 0;
    }

    /**
     * 加载城市列表数据
     */
    private void getAllCity() {
        final long count = AreaDao.getInstance(context).queryCount();
        if (count == 0 || count < 3000) {
            AreaDao.getInstance(context).deleteAll();
            NewActionHelp.qryCityName(bActivity, 1, new CityHandler());
            NewActionHelp.qryCityName(bActivity, 2, new CityHandler());
            NewActionHelp.qryCityName(bActivity, 3, new CityHandler());
        }
    }

    /**
     * 加载城市列表数据 监听事件
     */
    private class CityHandler
            extends
            ObjectHttpResponseHandler<List<Area>> {
        @Override
        public void onFailure(int statusCode, Header[] headers, String responseString, Throwable throwable) {
            Logger.e(responseString, throwable);
        }

        @Override
        public void onSuccess(int statusCode, Header[] headers, final List<Area> object, String responseString) {
            Logger.d("获取城市数据" + object.size() + "条，AreaType" + object.get(0).areaType);
            new Thread() {
                public void run() {
                    AreaDao.getInstance(bActivity).addList(object);
                }

                ;
            }.start();
        }

        @Override
        public Type getType() {
            return new TypeToken<List<Area>>() {
            }.getType();
        }
    }

    void startCheckVersion() {
        new QryNewVersionAction(context, AppConfig.getVersionCode(bActivity), new VersionListener()).start();
    }

    @Override
    public int leave(IUIPage<?> arg0) {
        return 0;
    }

    @Override
    public boolean handleBack() {
        if (null != forceUpdatePop && forceUpdatePop.isShowing()) return true;
        long curTime = System.currentTimeMillis();
        String appName = bActivity.getResources().getString(R.string.click_back_again, getTextString(R.string.app_name));
        if (DefaultConsts.lastRunBackTime == 0) {
            Toast.makeText(context, appName, Toast.LENGTH_SHORT).show();
            DefaultConsts.lastRunBackTime = curTime;
        } else {
            if (curTime - DefaultConsts.lastRunBackTime > 3000) {
                Toast.makeText(context, appName, Toast.LENGTH_SHORT).show();
                DefaultConsts.lastRunBackTime = curTime;
            } else {
                exit();
                return false;
            }
        }
        return true;
    }

    public static void clearPage() {
        if (null != pages && pages.size() > 0) {
            for (AbstractUIPage page : pages) {
                System.out.println("MainPage -->" + page.getClass().getSimpleName() + " -- dispose!!");
                page.dispose();
            }
            pages.clear();
        }
        pagerAdapter.notifyDataSetChanged();
        pages = null;
        instance = null;
    }

    public void exit() {
        if (Util.isNotEmpty(Const.phone_number)) {
            //			QyreaderPerferencesUtil.getInstance(bActivity, Const.phone_number).setLastPushMessageId(0L);
            QyreaderPerferencesUtil.getInstance(bActivity, Const.phone_number).setExistMainActivity(false);
        }
        BaseSimpleActivity.clearNotification(context, DefaultConsts.DOWNLOAD_NOTIFICATION_FLAG);
        BaseSimpleActivity.exit();
        clearPage();
        System.exit(0);
    }

    private String getTextString(int rId) {
        return bActivity.getResources().getString(rId);
    }

    @Override
    public void notifyView(int arg0, Bundle arg1) {
        if (pages != null && pages.size() > 0) {
            AbstractUIPage<MainActivity> page = pages.get(pageSelected);
            page.notifyView(arg0, arg1);
            switch (arg0) {
                case DefaultConsts.PAGE_ONRESUME_CODE:
                    //				qryUnReadTotal();
                    break;
                case DefaultConsts.MESSAGE_UNREAD_CHANGE_CODE:
                    //				boolean res = arg1.getBoolean("result");
                    //				vMessageUnRead.setVisibility(res ? View.VISIBLE : View.GONE);
                    break;
                case DefaultConsts.UPDATEUI_GETVERSIONINFO_OK:
                    showVersionDialog();
                    break;
                case DefaultConsts.UPDATEUI_GETVERSIONINFO_ERROR:
                    break;
            }
        }
    }

    void showVersionDialog() {
        if (versionInfo != null) {
            if (AppConfig.getVersionCode(bActivity) < versionInfo.versionCode2 && versionInfo.isHasNewVersion() && versionInfo.isReleased()) {
                versionDialog = new VersionDialog(bActivity);
                versionDialog.setPage(MainTabPage.this);
                versionDialog.setVersionInfo(versionInfo);
                versionDialog.setCancelable(false);
                versionDialog.SetForceUpdateClick(new VersionDialog.ForceUpdateClickListener() {

                    @Override
                    public void ForceUpdateClick(String FilePath) {
                        tempFilePath = FilePath;
                        forceUpdatePop = new PopupWindow(bActivity);
                        forceUpdatePop.setTouchInterceptor(new View.OnTouchListener() {

                            @Override
                            public boolean onTouch(View v, MotionEvent event) {
                                if (event.getAction() == MotionEvent.ACTION_OUTSIDE) {

                                    return true;
                                }
                                return false;

                            }

                        });
                        //								ForceUpdatePop
                        //
                        //								ForceUpdatePop
                        View Update_Version_View = LayoutInflater.from(bActivity).inflate(R.layout.update_version_popwindow, null);
                        forceUpdatePop.setContentView(Update_Version_View);
                        update_popup_cancel = (TextView) Update_Version_View.findViewById(R.id.update_version_text_cancel);
                        update_popup_cancel.setSelected(false);
                        update_popup_cancel.setVisibility(versionInfo.isForce() ? View.GONE : View.VISIBLE);
                        update_popup_progress = (ProgressBar) Update_Version_View.findViewById(R.id.update_version_pop_progressbar);
                        update_popup_progress.setMax(100);
                        update_popup_text_progress = (TextView) Update_Version_View.findViewById(R.id.update_version_text_progress);
                        forceUpdatePop.setWidth(ScreenUtil.screenWidth);
                        forceUpdatePop.setHeight(ScreenUtil.screenHeight);
                        forceUpdatePop.setBackgroundDrawable(new ColorDrawable(Color.argb(0, 0, 0, 0)));
                        forceUpdatePop.showAtLocation(curMyView, Gravity.CENTER, 0, 0);
                        QyreaderPerferencesUtil.getInstance(bActivity, Const.phone_number).setUpdateVersionDownLoadComplete(false);
                        final ForceUpdateTask Task = new ForceUpdateTask();
                        Task.execute(FilePath);

                        update_popup_cancel.setOnClickListener(new View.OnClickListener() {

                            @Override
                            public void onClick(View v) {
                                String Value = ((TextView) v).getText().toString();
                                if ("下载失败".equals(Value) || "取消".equals(Value)) {
                                    forceUpdatePop.dismiss();
                                    Task.cancel(true);
                                    FileUtil.delFile(SDcardUtil.getHomePath() + File.separator + AppConfig.getChannelName() + versionInfo.versionCode2 + ".apk");
                                    exit();
                                } else if ("升级".equals(Value)) {
                                    forceUpdatePop.dismiss();

                                    forceSetupApp(bActivity, tempFilePath);

                                }
                            }
                        });
                    }
                });
                versionDialog.show();

            }
        }
    }

    @Override
    public void setStatus(int arg0) {

    }

    @Override
    public View updateView(int arg0, ITaskResult arg1) {
        return null;
    }

    public void setSelectPage(int select) {
        if (pageSelected != select) {
            vpPager.setCurrentItem(select);
        }
    }

    @Override
    public void onClick(View v) {
        if (!NetworkUtil.isNetAvailable(bActivity)) {
            new NoNetDialog(bActivity).show();
            return;
        }
        switch (v.getId()) {
            case R.id.main_tab1:
                setSelectPage(TAG_TAB1);
                break;
            case R.id.main_tab2:
                setSelectPage(TAG_TAB2);
                break;
            case R.id.main_tab3:
                setSelectPage(TAG_TAB3);
                break;
            case R.id.main_tab4:
                setSelectPage(TAG_TAB4);
                break;
            case R.id.main_tab5:
                setSelectPage(TAG_TAB5);
                break;
        }

    }

    private class Adapter
            extends
            PagerAdapter {

        @Override
        public int getCount() {

            return pages == null ? 0 : pages.size();
        }

        @Override
        public boolean isViewFromObject(View arg0, Object arg1) {

            return arg0 == arg1;
        }

        @Override
        public Object instantiateItem(ViewGroup container, int position) {

            AbstractUIPage<MainActivity> page = pages.get(position);

            if (page.getView() == null) {
                page.createView(bActivity, DEFAULT_STATUS);
            }

            if (page.getView().getParent() == null) {
                container.addView(page.getView());
            }

            return page.getView();
        }

        @Override
        public void destroyItem(ViewGroup container, int position, Object object) {
            //AbstractUIPage<BaseBusinessActivity> page = pages.get(position);

            //container.removeView(page.getView());
        }

    }

    private class PageChangeListener
            implements
            ViewPager.OnPageChangeListener {

        @Override
        public void onPageScrollStateChanged(int arg0) {

        }

        @Override
        public void onPageScrolled(int arg0, float arg1, int arg2) {

        }

        @Override
        public void onPageSelected(int select) {
            onSelected(select);
        }

    }

    private void clickTab(int select) {
        vTab1.setSelected(select == TAG_TAB1 ? true : false);
        vTab2.setSelected(select == TAG_TAB2 ? true : false);
        vTab3.setSelected(select == TAG_TAB3 ? true : false);
        vTab4.setSelected(select == TAG_TAB4 ? true : false);
        vTab5.setSelected(select == TAG_TAB5 ? true : false);
    }

    private void onSelected(int select) {
        clickTab(select);
        pageSelected = select;
        page = pages.get(pageSelected);
        page.enter(null);
    }

    class VersionListener
            implements
            ActionListener {

        @Override
        public void OK(Object obj) {
            versionInfo = (AppInfo) obj;

            bActivity.getUIHandler().sendEmptyMessage(DefaultConsts.UPDATEUI_GETVERSIONINFO_OK);
        }

        @Override
        public void ERROR(int resultCode, String message) {
            bActivity.getUIHandler().sendEmptyMessage(DefaultConsts.UPDATEUI_GETVERSIONINFO_ERROR);
        }

        @Override
        public void HTTPERROR(int statusCode) {
            bActivity.getUIHandler().sendEmptyMessage(DefaultConsts.UPDATEUI_GETVERSIONINFO_ERROR);
        }

    }

    class ForceUpdateTask
            extends
            AsyncTask<String, Integer, Integer> {

        @Override
        protected Integer doInBackground(String... params) {

            if (versionInfo != null) {
                downLoadApk(versionInfo.fileUrl, params[0]);
            }

            return null;
        }

        @Override
        protected void onPostExecute(Integer result) {

            super.onPostExecute(result);
        }

        @Override
        protected void onCancelled() {

            File file = new File(tempFilePath);
            if (file.exists()) {
                file.delete();
            }
            super.onCancelled();
        }
    }

    private void downLoadApk(String url, String filePath) {

        InputStream is = null;
        FileOutputStream fos = null;
        File myTempFile = null;
        try {
            URL myURL = new URL(url);
            URLConnection conn;
            conn = myURL.openConnection();
            conn.connect();
            is = conn.getInputStream();
            if (is == null) {
                throw new Exception("stream is null");
            }

            myTempFile = new File(filePath);
            fos = new FileOutputStream(myTempFile);
            int total = conn.getContentLength();
            int curr = 0;
            int currentNum = 0;
            byte buf[] = new byte[51200];
            do {
                int numread = is.read(buf);
                curr = curr + numread;
//                int num = curr * 100 / total;
                int num = (int) (curr * 100.0 / total);
                currentNum = num;
                UpdateDownloadProgress(num);

                if (numread <= 0) {
                    break;
                }
                fos.write(buf, 0, numread);
            }
            while (true);
            //			NotifBar(myTempFile);
            UpdateDownloadProgress(100);
            QyreaderPerferencesUtil.getInstance(bActivity, Const.phone_number).setUpdateVersionDownLoadComplete(true);
        } catch (Exception e) {
            e.printStackTrace();
            //			NotifBar();
            UpdateDownloadProgress(-1);
        }

    }

    private void UpdateDownloadProgress(final int progress) {
        bActivity.runOnUiThread(new Runnable() {

            @Override
            public void run() {
                // TODO Auto-generated method stub
                update_popup_progress.setProgress(progress);
                if (progress == -1) {
                    update_popup_cancel.setText("下载失败");
                } else if (progress < 100) {
                    update_popup_text_progress.setText("已下载(" + progress + "%)");
                } else {
                    update_popup_text_progress.setText("下载完成");
                    update_popup_progress.setProgress(100);
                    update_popup_cancel.setVisibility(View.VISIBLE);
                    update_popup_cancel.setText("升级");
                    update_popup_cancel.setSelected(true);
                    forceUpdatePop.setOutsideTouchable(true);

                }

            }
        });
    }

    public void setupApp(Context context, String filePath) {
        if (context != null && (!TextUtils.isEmpty(filePath))) {
            Intent intent = new Intent(Intent.ACTION_VIEW);
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            intent.setDataAndType(Uri.fromFile(new File(filePath)), "application/vnd.android.package-archive");
            context.startActivity(intent);
        }

    }

    public void forceSetupApp(Context context, String filePath) {
        setupApp(context, filePath);
        exit();
    }

    /**
     * 预加载会话列表数据
     */
    private void preload() {
        //如果 登陆者身份为普通用户，说明该登陆者不需要显示显示聊天，因此不需要预加载会话列表数据
        if (Const.UserRole.equals("0")) {
            return;
        }
        NIMClient.getService(MsgService.class).queryRecentContacts().setCallback(new RequestCallback<List<RecentContact>>() {
            @Override
            public void onSuccess(List<RecentContact> recents) {
                ArrayList<String> pids = new ArrayList<String>();
                for (RecentContact r : recents) {
                    final String teamId = r.getContactId();
                    if (r.getAttachment() != null && r.getAttachment() instanceof DismissAttachment) {
                        continue;
                    }
                    if (r.getSessionType() == SessionTypeEnum.Team && !TeamDataCache.getInstance().isTeamInCache(r.getContactId())) {
                        queryTeamMember(teamId);
                    }
                    if (r.getSessionType() == SessionTypeEnum.P2P) {
                        pids.add(r.getContactId());
                    }
                }
                //TODO
                //				if(Const.UserRole != null){
                //					if("1".equals(Const.UserRole))
                //					if("2".equals(Const.UserRole))
                //				}
                if (pids.size() > 0) {
                    queryAccids(pids.toString());
                } else {
                    return;
                }
            }

            @Override
            public void onFailed(int code) {
                Logger.i("" + code);
            }

            @Override
            public void onException(Throwable exception) {
                Logger.e(exception);
            }
        });

        NIMClient.getService(TeamService.class).queryTeamList().setCallback(new RequestCallback<List<Team>>() {
            @Override
            public void onException(Throwable arg0) {
                Logger.e(arg0);
            }

            @Override
            public void onFailed(int arg0) {
                Logger.i("" + arg0);
            }

            @Override
            public void onSuccess(List<Team> arg0) {
                for (Team team : arg0) {
                    queryTeamMember(team.getId());
                }
            }
        });
    }

    private void queryAccids(String ids) {
        NewActionHelp.qryStaffInfoByAccIds(bActivity, ids, new ObjectHttpResponseHandler<List<TeamMemberX>>() {
            @Override
            public void onFailure(int statusCode, Header[] headers, String responseString, Throwable throwable) {
                Logger.e(throwable);
                Logger.i(responseString);
            }

            @Override
            public void onSuccess(int statusCode, Header[] headers, List<TeamMemberX> object, String responseString) {
                if (object != null && !object.isEmpty()) {
                    TeamMemberInfoCache.getInstance().add(object);
                }
            }

            @Override
            public Type getType() {
                return new TypeToken<List<TeamMemberX>>() {
                }.getType();
            }
        });
    }

    private void queryTeamMember(final String teamId) {
        if (TextUtils.isEmpty(teamId) || TeamMemberInfoCache.getInstance().getTeamMember(teamId) != null)
            return;
        NewActionHelp.qryMemberListByTeamId(bActivity, teamId, new ObjectHttpResponseHandler<List<TeamMemberX>>() {
            @Override
            public void onFailure(int statusCode, Header[] headers, String responseString, Throwable throwable) {
                Logger.e(throwable);
                Logger.i(responseString);
            }

            @Override
            public void onSuccess(int statusCode, Header[] headers, List<TeamMemberX> object, String responseString) {
                if (object != null && !object.isEmpty()) {
                    TeamMemberInfoCache.getInstance().addTeam(teamId, object);
                    TeamMemberInfoCache.getInstance().add(object);
                }
            }

            @Override
            public Type getType() {
                return new TypeToken<List<TeamMemberX>>() {
                }.getType();
            }
        });
    }
}
